<template>
  <Card style="height:900px">
  <Card style="width:350px;margin:150px auto">
    <Row type="flex" align="middle">
      <Col span="4">产品:</Col>
      <Col span="18">
      <Select v-model="productType" style="width:200px" >
        <Option v-for="item in productTypeDatas" :value="item.value" :key="item.value">{{ item.label }}</Option>
      </Select>
      </Col>
    </Row>
    <Row type="flex" align="middle">
      <Col span="4">流程:</Col>
      <Col span="18">
      <Select v-model="flow" style="width:200px" >
        <Option v-for="item in flowDatas" :value="item.value" :key="item.value">{{ item.label }}</Option>
      </Select>
      </Col>
    </Row>
    <Row type="flex" align="middle">
      <Col span="4">状态:</Col>
      <Col span="18">
      <Select v-model="status" style="width:200px" >
        <Option v-for="item in statusDatas" :value="item.value" :key="item.value">{{ item.label }}</Option>
      </Select>
      </Col>
    </Row>
    <Row type="flex" align="middle" style="margin-top:20px">
      <Col span="9"></Col>
      <Col span="14">
      <Button type="primary" @click="subProductFlow" size="small">提交</Button>
      </Col>
    </Row>
  </Card>
  </Card>
</template>
<script>

export default {
  data () {
    return {
      productType: null,
      productTypeDatas: [],
      status: null,
      statusDatas: [
        {
          label: '有效',
          value: 0
        },
        {
          label: '无效',
          value: 1
        }
      ],
      flow: null,
      flowDatas: []
    }
  },
  computed: {
    type () {
      return this.$route.query.type
    }
  },
  created () {
    this.$ajax = this.$util.ajax()
    this.initProductType()
    this.initFlow()
  },
  mounted () {},
  methods: {
    // 提交新增
    subProductFlow () {
      var params = {}
      params.actKey = this.flow
      // 获取流程名称
      var leg = this.flowDatas.length
      for (var i = 0; i < leg; i++) {
        var label = this.flowDatas[i].label
        var val = this.flowDatas[i].value
        if (this.flow === val) {
          params.actName = label
          break
        }
      }
      params.status = this.status
      params.productType = this.productType
      // 获取产品名称
      var length = this.productTypeDatas.length
      for (var j = 0; j < length; j++) {
        var label2 = this.productTypeDatas[j].label
        var val2 = this.productTypeDatas[j].value
        if (this.productType === val2) {
          params.productTypeName = label2
          break
        }
      }
      this.$ajax.post(this.$appContext.marvels_core_approve + 'approve/manager_pt/service/add', params)
        .then(re => {
          if (re.data.code === 'success') {
            this.$Message.success('操作成功!')
            this.$router.push({
              name: 'product_flow'
            })
          } else {
            this.$Message.error(re.data.data)
          }
        })
        .catch(er => {
        })
    },
    // 初始化流程
    initFlow () {
      var params = {}
      params.pageSize = 100000
      this.$ajax.post(this.$appContext.marvels_core_approve + 'approve/manager/service/query', params)
        .then(re => {
          var datas = re.data.data.list || []
          this.flowDatas = []
          datas.forEach(item => {
            if (item.actKey != null) {
              var sData = {}
              sData.value = item.actKey
              sData.label = item.actName
              this.flowDatas.push(sData)
            }
          })
        })
        .catch(er => {
        })
    },
    initProductType () {
      var params = {}
      params.productType = null
      params.version = null
      params.pageSize = 2000
      params.currentPage = 1

      this.$ajax.post(this.$appContext.marvels_core_product + 'product/mcpt/service/searchProduct', params)
        .then(re => {
          var datas = re.data.data.list || []
          this.productTypeDatas = []
          datas.forEach(item => {
            var sData = {}
            sData.value = item.productType
            sData.label = item.productTypeName
            this.productTypeDatas.push(sData)
          })
        })
        .catch(er => {
        })
    },
    handleRouteGo (path) {
      this.$router.push(path)
    }
  },
  watch: {
    $route (val) {}
  },
  props: {}
}
</script>

<style lang="less">
.xzqy-page {
  /*@media only screen and (min-width:1366px){
      .bottom-btn button:nth-of-type(1){
        margin-right:70px;
      }
    }
    @media only screen and (min-width:1200px){
      .bottom-btn button:nth-of-type(1){
        margin-right:40px;
      }
    }*/
}
</style>
